package com.qianya.weishi_server.common.result;

import lombok.Data;

import java.io.Serializable;

@Data
public class WebSocketResult<T> implements Serializable {
    private static final long serialVersionUID = -6120442765653688084L;


    private String code;
    private String msg;
    private T data;

    public WebSocketResult() {

    }

    public WebSocketResult(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public WebSocketResult(ErrorCode error) {
        this.code = error.getCode();
        this.msg = error.getMessage();
    }

    public WebSocketResult(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> WebSocketResult<T> success() {
        return new WebSocketResult<>(GenericErrorCode.WEBSOCKET_SUCCESS.getCode(), GenericErrorCode.WEBSOCKET_SUCCESS.getMessage());
    }

    public static <T> WebSocketResult<T> success(T data) {
        return new WebSocketResult<>(GenericErrorCode.WEBSOCKET_SUCCESS.getCode(), GenericErrorCode.WEBSOCKET_SUCCESS.getMessage(), data);
    }


}
